home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / comm / tcp / AmiTCPsdk_40.lha / AmiTCP-4.0 / src / examples / serv / in.example.c next >
C/C++ Source or Header  |  1994-09-29  |  1KB  |  55 lines

  1. RCS_ID_C="$Id: in.example.c,v 4.1 1994/09/30 00:12:35 jraja Exp $";
  2. /*
  3.  *      in.example.c - an example server to be started by inetd
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <unistd.h>
  13. #include <fcntl.h>
  14. #include <errno.h>
  15. #include <string.h>
  16. #include <clib/netlib_protos.h>
  17.  
  18. void
  19. main(int argc, char **argv)
  20. {
  21.   char buffer[81];
  22.   char *cp, *cr;
  23.  
  24.   /*
  25.    * If init_inet_daemon() fails, we continue and work in normal stdio mode,
  26.    * i.e., the stdio is not bound to a socket. In this case, none of the
  27.    * bsdsocket.library functions can be used on the files 0, 1 or 2. This
  28.    * doesn't matter, since we aren't going to use any of them anyway.
  29.    */
  30.   int sock = init_inet_daemon();
  31.   if (sock >= 0)
  32.     set_socket_stdio(sock);
  33.   /* else use normal stdio */
  34.  
  35.   /*
  36.    * Simple loop that gets one line, and then puts it out in reverse.
  37.    */
  38.   while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
  39.     /*
  40.      * Print the text in reverse
  41.      */
  42.     for (cp = buffer + strlen(buffer) - 1, cr = NULL; cp >= buffer; cp--) {
  43.       if (*cp == '\n' || *cp == '\r')
  44.     cr = cp;
  45.       else
  46.     fputc(*cp, stdout);
  47.     }
  48.     /*
  49.      * print end of line if it was found
  50.      */
  51.     if (cr != NULL)
  52.       fputs(cr, stdout);
  53.   }
  54. }
  55.